﻿#define _CRT_SECURE_NO_WARNINGS 

//strncmp模拟实现
//char * strncpy ( char * destination, const char * source, size_t num );
//拷⻉num个字符从源字符串到⽬标空间。
//如果源字符串的⻓度⼩于num，则拷⻉完源字符串之后，在⽬标的后边追加0，直到num个。

#include <stdio.h>
#include <string.h>
char* mystrncpy(char* dest, const char* src, size_t num);
int main()
{
	char arr1[] = "abcdefg";
	char arr2[10] = "xxxxxxxx";
	mystrncpy(arr2, arr1, 5);
	return 0;
}



char* mystrncpy(char* dest, const char* src, size_t num)
{
	char* ret = dest;
	while (num--)
	{
		*dest = *src;
		dest++;
		if (*src == '\0')
		{
			;
		}
		else
		{
			src++;
		}
	}
	return ret;
}


